/************************************************************************************
 * 
 *  Umbraco Data Layer
 *  MIT Licensed work
 *  ?008 Ruben Verborgh
 * 
 ***********************************************************************************/

using System;
using System.Data.Common;
using System.Reflection;
using curbside.SqlHelper.SqlHelpers.SqlServer;
using curbside.SqlHelper.SqlHelpers.MySql;

namespace curbside.SqlHelper
{
    /// <summary>
    /// The DataLayerHelper class is the main interface to the data layer.
    /// </summary>
    public class DataLayerHelper
    {

        #region Public Methods
        /// <summary>
        /// Creates a SQL helper for the specified connection string.
        /// </summary>
        /// <param name="connectionString">The connection string containing the SQL helper type.</param>
        /// <returns>A new SQL helper.</returns>
        /// <remarks>This method will change to allow the addition of external SQL helpers.</remarks>
        public static ISqlHelper CreateSqlHelper(string connectionString)
        {
            /* check arguments */
            if (String.IsNullOrWhiteSpace(connectionString))
                throw new ArgumentNullException("connectionString");

            /* try to parse connection string */
            DbConnectionStringBuilder connectionStringBuilder = new DbConnectionStringBuilder();
            try
            {
                connectionStringBuilder.ConnectionString = connectionString;
            }
            catch (Exception ex)
            {
                throw new ArgumentException("Bad connection string.", "connectionString", ex);
            }

            return new SqlServerHelper(connectionStringBuilder.ConnectionString);
        }

        #endregion
    }
}
